﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Web;

namespace lxwmvc
{
    public class jiandansql
    {
        /// <summary>
        /// 执行sql语句 返回int
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int getint(string sql)
        {
            return sqlhelper.executescalar(sql).toint32();
        }

        public static int execute(string sql)
        {
            return sqlhelper.executenonquery(sql).toint32();
        }

        /// <summary>
        /// 执行sql语句，返回decimal
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static decimal getdecimal(string sql)
        {
            return sqlhelper.executescalar(sql).todecimal();
        }

        /// <summary>
        /// 执行sql语句 返回string
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static string getstring(string sql)
        {
            return sqlhelper.executescalar(sql).tostr();
        }

        /// <summary>
        /// 执行sql语句,返回datarows
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataRowCollection getrows(string sql)
        {
            return sqlhelper.executedataset(sql).Tables[0].Rows;
        }

        /// <summary>
        /// 执行sql语句,得到一条信息
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataRow getonerow(string sql)
        {
            DataTable dt = sqlhelper.executedataset(sql).Tables[0];
            if (dt.Rows.Count == 0)
                return null;

            return dt.Rows[0];
        }
    }
}
